package org.benben;

import java.util.HashMap;

class DomNode
{
    private String tagName;
    private String value;
    private HashMap<String, String> property;
    private DomNode nextSibling;
    private DomNode leftChild;
    private DomNode parent;
    private StringBuilder strBuilder;
        
    public DomNode()
    {
        this.tagName = "";
        this.value = "";
        this.property = new HashMap<String, String>();
        this.leftChild = null;
        this.nextSibling = null;
        this.parent = null;
    }
        
    public DomNode(String tagName, String value, HashMap<String, String> property)
    {
        this.tagName = tagName;
        this.value = value;
        this.property = property;
    } 
        
    public void setParent(DomNode parent)
    {
        this.parent = parent;
    }
        
    public DomNode getParent()
    {
        return this.parent;
    }
        
    public void setLeftChild(DomNode child)
    {
        this.leftChild = child;
    }
        
    public DomNode getLeftChild()
    {
        return this.leftChild;
    }
        
    public void setNextSibling(DomNode nextSibling)
    {
        this.nextSibling = nextSibling;
    }
        
    public DomNode getNextSibling()
    {
        return this.nextSibling;
    }
        
    public void setTagName(String tagName)
    {
        this.tagName = tagName;
    }

    public String getTagName()
    {
        return this.tagName;
    }

    public void setValue(String value)
    {
        this.value = value;
    }
        
    public String getValue()
    {
        return this.value;
    }
        
    public void setProperty(HashMap<String, String> property)
    {
        this.property = property;
    }
        
    public void setProperty(String key, String value)
    {
            
    }
        
    public HashMap<String, String> getProperty()
    {
        return this.property;
    }
        
    public String getProperty(String propertyName)
    {
        if(property.containsKey(propertyName))
            return property.get(propertyName);
            
        else
            return "";
    }
}

public class DomTree
{
    private DomNode root;
    
    public DomTree()
    {
        this.root = null;
    }
    
    public DomTree(DomNode newNode)
    {
        
    }
    
    public void addDomNode(DomNode parent, DomNode leftSibling, DomNode leftChild, DomNode newNode)
    {
        
    }
    
    public void preOrder()
    {
        preOrder(this.root);
    }
    
    public void preOrder(DomNode domNode)
    {
        if(domNode == null)
            return;
        
        System.out.println("Node value:[" + domNode.getValue() + "]");
        
        DomNode current = domNode.getLeftChild();
        preOrder(current);
        
        current = domNode.getNextSibling();
        while(current != null)
        {
            preOrder(current);
            current = current.getNextSibling();
        }
    }
    
    public void inOrder()
    {
        inOrder(this.root);
    }
    
    public void inOrder(DomNode domNode)
    {
        if(domNode == null)
            return;
        
        DomNode current = domNode.getLeftChild();
        inOrder(current);
        
        System.out.println("Node value:[" + domNode.getValue() + "]");

        current = domNode.getNextSibling();
        while(current != null)
        {
            inOrder(current);
            current = current.getNextSibling();
        }
    }
    
    public void postOrder()
    {
        postOrder(this.root);
    }
    
    public void postOrder(DomNode domNode)
    {
        if(domNode == null)
            return;
        
        DomNode current = domNode.getLeftChild();
        postOrder(current);
        
        current = domNode.getNextSibling();
        while(current != null)
        {
            postOrder(current);
            current = current.getNextSibling();
        }
        
        System.out.println("Node value:[" + domNode.getValue() + "]");
    }
    
    public void traverse()
    {
        traverse(this.root, "INORDER");
    }        
    
    public void traverse(DomNode domNode, String type)
    {
        if(type.equals("PREORDER") == true)
            preOrder();
        else if(type.equals("POSTORDER") == true)
            postOrder();
        else if(type.equals("INORDER") == true)
            inOrder();
        else
            inOrder();
    }
    
    public DomNode getHead()
    {
        return null;
    }
    
    public DomNode getBody()
    {
        return null;
    }
    
    public DomNode[] getTagByName()
    {
        return null;
    }
    
    public String[] getHyperLinks()
    {
        return null;
    }
}

